<template>
    <div>
        <el-main>
            <el-page-header @back="goBack">
            </el-page-header>
            <el-row :gutter="20">
                <el-col :span="20" :offset="2">
                    <el-card v-for="(data,index) in formdata" :key="index" shadow="hover">
                        <el-row :gutter="20" style="line-height:30px">
                            <el-col :span="4">
                                <el-image :src="data.image" fit="cover" style="width: 100px; height: 100px"></el-image>
                            </el-col>
                            <el-col :span="2">
                                <el-image :src="shuxian.url" fit="cover" style="width: 100px; height: 100px"></el-image>
                            </el-col>
                            <el-col :span="10">
                                <span class="name">{{data.storeName}}</span>
                                <br>
                                <span class="appraise">5.0分 </span>
                                <span class="sail">月售3000份</span>
                                <br>
                                <span class="description">总价:￥{{data.amount}}</span>
                            </el-col>
                            <el-col :span="2" :offset="2">
                                <br><br>
                                <el-button type="warning" round icon="el-icon-delete" @click="toCancel(data)">取消
                                </el-button>
                            </el-col>
                            <el-col :span="2">
                                <br><br>
                                <el-button type="danger" round icon="el-icon-eleme" @click="buy(data)">购买</el-button>
                            </el-col>
                        </el-row>
                    </el-card>
                    <el-empty :image-size="200" v-if="isEmpty"></el-empty>
                </el-col>
            </el-row>
        </el-main>
    </div>
</template>
<script>
import { getShoppingCartData, cancel } from '@/utils/modules/customer.js'
export default {
    mounted() {
        this.getData()
    },
    data() {
        return {
            formdata: [],
            shuxian: {
                url: '/images/shuxian.png'
            },
            isEmpty:false
        }
    },
    methods: {
        getData() {
            getShoppingCartData().then(res => {
                this.formdata = JSON.parse(JSON.stringify(res.data.itemList))
                if(this.formdata == 0){
                    this.isEmpty = true
                }
                console.log(this.formdata)
            }).catch(err => {
                if(this.formdata == 0){
                    this.isEmpty = true
                }
                this.$message({
                    type: 'error',
                    message: err.message,
                    showClose: true
                })
            })
        },
        toCancel(data) {
            cancel({ id: data.id }).then(res => {
                this.$message({
                    type: 'success',
                    message: res.message,
                    showClose: true
                })
                setTimeout(() => {
                    this.$router.go(0)
                }, 500)
            }).catch(err => {
                this.$message({
                    type: 'error',
                    message: err.message,
                    showClose: true
                })
            })
        },
        buy(data) {
            this.$router.push({
                path: '/pay',
                query: {
                    'order':JSON.stringify({
                        'dishId':data.dishId,
                        'dishNumber':data.dishNumber,
                        'dishTotalNumber':data.dishTotalNumber,
                        'amount':data.amount,
                        'flavor':data.flavor,
                        'shoppingCartId':data.id,
                        'marketerId':data.marketerId
                    })
                }
            })
        },
        goBack() {
            this.$router.push({
                path:'/customer'
            })
        }
    }
}
</script>
<style>
/* 名字 */
.name {
    font-weight: 500;
    font-size: large;
    /* padding-left: 50%; */
}

/* 评分 */
.appraise {
    font-size: small;
    color: red;
    font-weight: 100;
    /* padding-left: 50%; */
}

/* 月售 */
.sail {
    font-size: small;
    font-weight: 100;
    color: #475669;
    /* padding-left: 50%; */
}

.description {
    font-size: small;
    color: lightgray;
    font-weight: 400;
}
</style>